from django.db import models


# Create your models here.


class GameClass(models.Model):
    class_name = models.CharField(max_length=30, verbose_name='类名')
    top = models.BooleanField(default=False, verbose_name='主页显示')

    def __str__(self):
        return str(self.class_name)

    class Meta:
        verbose_name_plural = '游戏分类'


class Game(models.Model):
    name = models.CharField(max_length=30, verbose_name='游戏名')
    top = models.BooleanField(default=False, verbose_name='主页显示')
    order = models.IntegerField(default=0, verbose_name='主页展示顺序')
    touched = models.IntegerField(verbose_name='点击量')
    downloaded = models.IntegerField(verbose_name='下载量')

    def __str__(self):
        return str(self.name)

    class Meta:
        verbose_name_plural = '游戏'


class GameDown(models.Model):
    belong_game = models.OneToOneField(to=Game, on_delete=True, verbose_name='所属游戏')
    android = models.FileField(upload_to='game_android', blank=True, verbose_name='安卓下载')
    ios = models.FileField(upload_to='game_ios', blank=True, verbose_name='苹果下载')
    last_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    def __str__(self):
        return str(self.belong_game)

    class Meta:
        verbose_name_plural = '游戏下载'



class GameFactory(models.Model): #厂商描述
    name = models.CharField(max_length=50, verbose_name='厂商名称')
    address = models.CharField(max_length=255, verbose_name='地址')
    phone = models.CharField(max_length=20, verbose_name='联系方式')
    QQ = models.CharField(max_length=10, verbose_name='QQ')
    weibo = models.CharField(max_length=30, verbose_name='微博')
    e_mail = models.EmailField(verbose_name='E-mail')

    def __str__(self):
        return str(self.name)

    class Meta:
        verbose_name_plural = '游戏厂商'


class GameDetail(models.Model): #游戏详情
    ONLINE = (
        ('1', '单机'),
        ('2', '联机'),
    )

    GTYPE = (
        ('1', '手游'),
        ('2', '页游')
    )
    belong_game = models.OneToOneField(to=Game, on_delete=True, verbose_name='所属游戏')
    icon = models.ImageField(upload_to='game_icon', verbose_name='图标')
    image = models.ImageField(upload_to='game_image', verbose_name='大图')
    description = models.CharField(max_length=100, verbose_name='简述')
    detail = models.TextField(verbose_name='详情')
    level = models.FloatField(verbose_name='星级')
    price = models.FloatField(default=0, verbose_name='价格')
    version = models.CharField(max_length=50, verbose_name='版本号')
    size = models.CharField(max_length=100, verbose_name='文件大小')
    factory = models.ForeignKey(to=GameFactory, on_delete=True, verbose_name='游戏厂商')
    line = models.CharField(max_length=1, choices=ONLINE, verbose_name='单/联机')
    type = models.CharField(max_length=1, choices=GTYPE, verbose_name='游戏类型', default='1')
    belong_class = models.ManyToManyField(GameClass, related_name='rel_game', verbose_name='游戏类别')

    def __str__(self):
        return str(self.belong_game)

    class Meta:
        verbose_name_plural = '游戏详情'



class GameDetailIma(models.Model):
    belong_detial = models.ForeignKey(to=GameDetail, on_delete=True, related_name='rel_game_image', verbose_name='所属游戏详情')
    image = models.ImageField(upload_to='game_image', verbose_name='游戏轮播图')

    def __str__(self):
        return str(self.belong_detial)

    class Meta:
        verbose_name_plural = '游戏轮播图'
